#ifndef __GlTextureManager_h__
#define __GlTextureManager_h__

#include <d3d11.h>
#include <vector>
#include "Utility.h"

namespace GraphicLibrary
{
	class TextureManager
	{
		public:
			enum ExceptionList
			{
				ElFileLoadError
			};

			~TextureManager();
			ID3D11ShaderResourceView* getTexture(const char *fileName);
			inline static void Init(ID3D11Device *device)
			{
				if(msSingleton)
					delete msSingleton;
				msSingleton = new TextureManager(device);
			}
			inline static TextureManager* GetSingleton()	{return msSingleton;}
		private:
			class Content
			{
				public:
					const char*					mName;
					ID3D11ShaderResourceView*	mTexture;

					inline Content(const char *mName, ID3D11ShaderResourceView *texture)
						: mName(Utility::copyStr(mName))
						, mTexture(texture)
					{
						mTexture->AddRef();
					}
					inline ~Content()
					{
						delete [] mName;
						mTexture->Release();
					}
			};
			typedef std::vector<Content*>	ContentArray;
			ID3D11Device*	mDevice;
			ContentArray	mTextures;
			static TextureManager*	msSingleton;

			TextureManager(ID3D11Device *device)
				: mDevice(device)
			{}
			ContentArray::iterator findPlace(const char *name) const;
			ID3D11ShaderResourceView* createTexture(const char *fileName) const;
	};
}

#endif // __GlTextureManager_h__
